package com.huawei.rbac.enums;

import java.util.stream.Stream;

/**
 * 订单状态枚举类
 *
 * @author luohua
 * @date 2021/7/7
 */
public enum OrderStatusEnums {

    // 0、待审核 1、待收货 2、待收货(部分收货) 3、已收货  4、已作废 5、已拒绝

    PENDING_REVIEW(0, "待审核"),

    TOBE_STORED(1, "待收货"),

    PARTIAL_STORAGE(2, "待收货(部分收货)"),

    HAS_BEEN_STORED(3, "已收货"),

    ABOLISHED(4, "已作废"),

    REJECTED(5, "已拒收");


    private final Integer code;
    private final String desc;

    OrderStatusEnums(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getDesc() {
        return this.desc;
    }



    /**
     * 通过code获取订单状态desc
     *
     * @param code
     * @return
     */
    public static String getDescByCode(Integer code) {

        for (OrderStatusEnums desc : OrderStatusEnums.values()) {
            if (desc.getCode().equals(code)) {
                return desc.getDesc();
            }
        }
        return null;
    }


    /**
     * 通过code获取订单状态desc
     *
     * @param code
     * @return
     */
    public static OrderStatusEnums getOrderStatusEnums(Integer code) {

        return Stream.of(OrderStatusEnums.values())
                .filter(t -> t.getCode().equals(code))
                .findFirst().orElse(null);
    }


    public static void main(String[] args) {

        OrderStatusEnums enums = getOrderStatusEnums(1);
        System.out.println(enums.getDesc());

        System.err.println("desc= " + getDescByCode(1));
    }

}


